#include"DEMORenderComponent.h"
#include"DEMORenderComponentManger.h"

DEMORenderComponent::DEMORenderComponent()
{
	_spr = NULL;

	_bIsActive = true;
	_bIsHide = false;

	//registerActor();
}

DEMORenderComponent::~DEMORenderComponent()
{
	if(_spr != NULL)
	{
		DEMORenderComponentManger *rcm = DEMORenderComponentManger::getRenderComponentManager();
		rcm->unregistComponent( (DEMORenderComponent*)this );

		delete _spr;
		_spr = NULL;
	}	
}

void DEMORenderComponent::initRes(char* texName,char* dataName)
{
	if(_spr != NULL)
	{
		delete _spr;
		_spr = NULL;
	}

	_spr = new DEMOSprite(texName,dataName);
	DEMORenderComponentManger *rcm = DEMORenderComponentManger::getRenderComponentManager();
	rcm->registComponent( (DEMORenderComponent*)this );

	_rframeIdx = _rx = _ry = 0 ;
	_rrot = 0.0f;
	_rscale = 1.0f;
}

void DEMORenderComponent::destroyRes()
{
	if(_spr != NULL)
	{
		DEMORenderComponentManger *rcm = DEMORenderComponentManger::getRenderComponentManager();
		rcm->unregistComponent( (DEMORenderComponent*)this );

		delete _spr;
		_spr = NULL;
	}
}

bool DEMORenderComponent::render()
{
	_spr->paintFrame( _rframeIdx , _rx,_ry,0,0,_rrot,_rscale,_rcol,_brtrans);
	return false;
}

//void DEMORenderComponent::doHeartBeat()
//{
//
//}

void DEMORenderComponent::setRenderParam(int fidx,int x,int y,float rot,float scale,DWORD col,bool btrans)
{
	_rframeIdx = fidx;
	_rx = x;
	_ry = y;
	_rrot = rot;
	_rscale = scale;
	_rcol = col;
	_brtrans = btrans;
}